# -*- coding:utf-8 -*-
# ==========================================
#       Author: ZiChen
#        Mail: 1538185121@qq.com
#         Time: 2021/06/06
#           Version:
#             Description:
# ==========================================
from mutagen.id3 import ID3, APIC, TIT2, TPE1, TALB
version = '0.3'  # 插件版本
name = 'MP3Edit'  # 插件名


def edit(path, info):
    '''
    修改MP3歌曲信息
    path 歌曲路径
    artist 参与创作的艺术家
    album 唱片集
    title 标题
    picData 歌曲封面图片二进制
    '''
    songFile = ID3(path)
    songFile.update_to_v23()  # 把可能存在的旧版本升级为2.3
    if info['picData'] != 'None':
        songFile['APIC'] = APIC(  # 插入封面
            encoding=3,
            mime='image/jpeg',
            type=3,
            desc=u'Cover',
            data=info['picData']
        )
    if info['title'] != 'None':

        songFile['TIT2'] = TIT2(  # 插入歌名
            encoding=3,
            text=info['title']
        )
    if info['artist'] != 'None':
        songFile['TPE1'] = TPE1(  # 插入第一演奏家、歌手、等
            encoding=3,
            text=info['artist']
        )
    if info['album'] != 'None':
        songFile['TALB'] = TALB(  # 插入专辑名
            encoding=3,
            text=info['album']
        )
    songFile.save()
